package my.avoskagae.service.rpc.server;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import my.avoskagae.service.rpc.client.AuthUserService;
import my.avoskagae.utils.UserInfo;

public class AuthUserServiceImpl extends RemoteServiceServlet implements AuthUserService {

	private static final long serialVersionUID = 1L;

	@Override
	public UserInfo getUserInfo(String destinationURL) {
		UserInfo ui = new UserInfo();
		UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        
        if (user!=null){
        	ui.setNickname(user.getNickname());
        } else {
        	ui.setNickname("ANONYMOUS");
        }
        ui.setLogInLink(userService.createLoginURL(destinationURL));
        ui.setLogOutLink(userService.createLogoutURL(destinationURL));
		return ui;
	}

}
